﻿using System.Transactions;
using Bootstrap.AutoMapper;
using DogshowRepository;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace Dogshow.Linq2SQLRepository.Test
{
    [TestClass]
    public class IzlozbeRepositoryFixtures
    {
        private IIzlozbeRepository m_Respoitory;

        [ClassInitialize]
        public static void ClassInit(TestContext ctx)
        {
            Bootstrap.Bootstrapper.With.AutoMapper().Start();
            var model = new DogshowModel();
            if (model.DatabaseExists())
            {
                model.DeleteDatabase();
            }
            model.CreateDatabase();
            model.ExecuteCommand("INSERT INTO Mesta VALUES ('21000', 'NOVI SAD')");
            model.ExecuteCommand("INSERT INTO KinoloskaDrustva VALUES ('KD Novi Sad', 'Jovana Đorđevića 4', 1, NULL, NULL, NULL, NULL)");
            model.ExecuteCommand("INSERT INTO Izlozbe VALUES (1, 'CACIB Novi Sad', '50. Ljubilarna međunarodna izložba pasa svih rasa Novi Sad 2012', '2012/7/13', NULL, '08:00 Prijava', NULL, NULL, 0)");
            model.ExecuteCommand("INSERT INTO Titule VALUES('C.A.C.I.B')");
            model.ExecuteCommand("INSERT INTO Titule VALUES('Res C.A.C.I.B')");
            model.ExecuteCommand("INSERT INTO Titule VALUES('C.A.C')");
            model.ExecuteCommand("INSERT INTO Titule VALUES('Res C.A.C')");
        }


        [TestInitialize]
        public void TestInit()
        {
            m_Respoitory = new IzlozbeRepository();
        }

        [TestMethod]
        public void SacuvajTituleIzlozbe()
        {
            using (new TransactionScope())
            {
                // Act
                m_Respoitory.SacuvajTitule(1, new[] { 1, 2 });

                // Assert
                var titule = m_Respoitory.VratiTituleIzlozbe(1);
                Assert.AreEqual(2, titule.Count());
                Assert.AreEqual("C.A.C.I.B", titule.ElementAt(0).Naziv);
                Assert.AreEqual("Res C.A.C.I.B", titule.ElementAt(1).Naziv);    
            }
        }
    }
}